import './assets/main.scss'
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-persistedstate-plugin'
import router, { setRoutes } from '@/router'
import App from './App.vue'
import ElementPlus, { ElMessageBox } from 'element-plus'
import 'element-plus/dist/index.css'
import locale from 'element-plus/es/locale/lang/zh-cn'

//引入element图标
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
// 创建 Pinia 实例
const pinia = createPinia()

document.title = '音驹实践教学管理平台'

const persist = createPersistedState()

pinia.use(persist) // 使用持久化插件
app.use(pinia) // 在应用中使用 Pinia
setRoutes()
app.use(router) // 在应用中使用路由
app.use(ElementPlus, { locale })
app.mount('#app') // 挂载应用

app.config.globalProperties.$myConfirm = async function (text) {
  try {
    await ElMessageBox.confirm(text, '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    return true
  } catch {
    return false
  }
}

import Particles from '@tsparticles/vue3'
import { loadSlim } from '@tsparticles/slim'
app.use(Particles, {
  init: async engine => {
    await loadSlim(engine)
  }
})
